local skill = fk.CreateSkill{
  name = "tea__xunde"
}
---@type TrigSkelSpec<TrigFunc>
local xunde = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) or player:getMark("@@xunde_prohibit-turn") > 0 then return false end
    for _, move in ipairs(data) do
      if move.from == player or (move.toArea == Player.Hand and move.to == player) then
        for _, info in ipairs(move.moveInfo) do
          if (info.fromArea == Player.Hand and move.from == player)
          or (move.toArea == Player.Hand and move.to == player) then
            return true
          end
        end
      end
    end
    return
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return #player:getCardIds(Player.Hand) == #p:getCardIds(Player.Hand)
    end)
    local choose = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      skill_name = skill.name,
      prompt = "#tea__xunde-choose"
    })
    if #choose > 0 then
      event:setCostData(self, choose)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self)[1]
    if to == player then
      room:setPlayerMark(player, "@@xunde_prohibit-turn", 1)
      room:invalidateSkill(player, skill.name, "-turn")
    end
    to:drawCards(1, skill.name)
  end
}
skill:addEffect(fk.AfterCardsMove, xunde)
return skill